/*
============================================================================
 Name        : StreamBuffer.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CStreamBuffer declaration
============================================================================
*/

#ifndef STREAMBUFFER_H
#define STREAMBUFFER_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include <f32file.h>
#include "logger.h"

class CStreamReader;
class CStreamWriter;

class CStreamBuffer : public CBase
{
public: // Constructors and destructor
	IMPORT_C CStreamBuffer();
	IMPORT_C void ConstructL();

	IMPORT_C ~CStreamBuffer();


public: //new functions
	IMPORT_C void Start();

	void SetReader(CStreamReader* aReader) { iReader = aReader; }
	void SetWriter(CStreamWriter* aWriter) { iWriter = aWriter; }

	TBool IsReadyToWrite(TInt aLength);
	IMPORT_C void Write(TDesC8& aChunk);

	TInt GetBytesReadyToRead();
	void Read(TDes8* aBuffer, TInt aLength);

	TBool IsFinished() { return iFinished; }
	void Finished() { iFinished = ETrue; }


private: //new functions
	TInt CalculateDifference(TInt aPos1, TInt aPos2);


private: //data
	//Buffer sizes
	TInt iBufferSize;

	//Main buffer
	TUint8* iBuffer;
	TPtr8 iBufferPtr;

	//Writing objects
	CStreamReader* iReader;
	TInt iPosWritten;

	//Reading objects
	CStreamWriter* iWriter;
	TInt iPosRead;

	//Mark if buffer is finished
	TBool iFinished;

	//Logger
	CLogger* iLogger;
};

#endif // STREAMBUFFER_H
